package org.jivesoftware.smackx.workgroup.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class MetaDataUtils
{
  public static Map parseMetaData(XmlPullParser paramXmlPullParser)
    throws XmlPullParserException, IOException
  {
    Object localObject;
    Hashtable localHashtable;
    int i;
    if ((paramXmlPullParser.getEventType() == 2) && (paramXmlPullParser.getName().equals("metadata")) && (paramXmlPullParser.getNamespace().equals("http://jivesoftware.com/protocol/workgroup")))
    {
      localHashtable = new Hashtable();
      i = paramXmlPullParser.nextTag();
      if ((i == 3) && (paramXmlPullParser.getName().equals("metadata")))
        localObject = localHashtable;
    }
    while (true)
    {
      return localObject;
      String str1 = paramXmlPullParser.getAttributeValue(0);
      String str2 = paramXmlPullParser.nextText();
      if (localHashtable.containsKey(str1))
        ((List)localHashtable.get(str1)).add(str2);
      while (true)
      {
        while (true)
          i = paramXmlPullParser.nextTag();
        ArrayList localArrayList = new ArrayList();
        localArrayList.add(str2);
        localHashtable.put(str1, localArrayList);
      }
      localObject = Collections.EMPTY_MAP;
    }
  }

  public static String serializeMetaData(Map paramMap)
  {
    Iterator localIterator1;
    StringBuilder localStringBuilder = new StringBuilder();
    if ((paramMap != null) && (paramMap.size() > 0))
    {
      localStringBuilder.append("<metadata xmlns=\"http://jivesoftware.com/protocol/workgroup\">");
      localIterator1 = paramMap.keySet().iterator();
    }
    while (true)
    {
      Object localObject1;
      Object localObject2;
      do
      {
        if (!(localIterator1.hasNext()))
        {
          localStringBuilder.append("</metadata>");
          return localStringBuilder.toString();
        }
        localObject1 = localIterator1.next();
        localObject2 = paramMap.get(localObject1);
        if (localObject2 instanceof List)
        {
          Iterator localIterator2 = ((List)paramMap.get(localObject1)).iterator();
          while (true)
          {
            if (!(localIterator2.hasNext()));
            String str = (String)localIterator2.next();
            localStringBuilder.append("<value name=\"").append(localObject1).append("\">");
            localStringBuilder.append(StringUtils.escapeForXML(str));
            localStringBuilder.append("</value>");
          }
        }
      }
      while (!(localObject2 instanceof String));
      localStringBuilder.append("<value name=\"").append(localObject1).append("\">");
      localStringBuilder.append(StringUtils.escapeForXML((String)localObject2));
      localStringBuilder.append("</value>");
    }
  }
}